/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import ejb.Calendarejb;
import ejb.Loginejb;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @author user
 */
@Named
@SessionScoped

public class Loginbean implements Serializable {

    @Inject
    Loginejb logejb;

    @Inject
    Calendarejb calejb;

    private String username;
    private String password;
    private String isLogged = null;

    public Loginbean() {
    }

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String name) {
        this.username = name;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getisLogged() {
        return isLogged;
    }

    public void setIsNotLogged() {
        isLogged = null;
    }

    public String login() {

        if (logejb.checkLogged(this.username, this.password) != null) {
            this.isLogged = logejb.loggedUser();
            calejb.loadCalendar(this.username);
            return "/s/user/calendar?faces-redirect=true";
        } else {
            this.isLogged = null;
        }
        return "/error2?faces-redirect=true";

    }

    public String loggedUser() {
        return this.username;
    }

    public String logOut() {

        setIsNotLogged();
        return "/login?faces-redirect=true";

    }
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
}
